//
//  QJTableVCManager.m
//  QuanJieShopProject
//
//  Created by apple on 2018/1/30.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJTableVCManager.h"
#import "QJNavigationController.h"
@implementation QJTableVCManager
#pragma mark -- 单例方法
+(QJTableVCManager *)shareManager{
    static QJTableVCManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[QJTableVCManager alloc]init];
    });
    return manager;
}
#pragma mark -- get方法
-(QJManagerVC *)managerVC{
    if (!_managerVC) {
        _managerVC = [[QJManagerVC alloc]initWithMainViewController:self.mainTabBarController];
    }
    return _managerVC;
}
-(UITabBarController *)mainTabBarController{
    if (!_mainTabBarController) {
        _mainTabBarController = [[UITabBarController alloc]init];
        //tabbar的界面  YFShopRegisterVC  QJHomeVC YFShopkeeperOrderVC
        NSArray *viewControllerNames = @[@"QJHomeVC",@"QJShopCarVC",@"YFNearVC",@"QJShouKuanVC",@"QJMineVC"];
        //tabbar的名字
        NSArray *titleNames = @[@"首页",@"购物车",@"附近",@"收款",@"我的"];
        //tabbar的图片 tab_money
        // kong 是个空图片,如果不设置,"附近"字体选中状态颜色一直是蓝色的
        NSArray *titleImages = @[@"tab_home",@"tab_car",@"tab_near",@"tab_shoukuan",@"tab_mine"];
        //3个元素的数组
        NSMutableArray *navArray = [NSMutableArray arrayWithCapacity:5];
        
        // 红色
        UIColor *redColor = YFColor_Red;
        //通过界面的名字(字符串)获得我们的类
        [viewControllerNames enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            Class class = NSClassFromString(viewControllerNames[idx]);
            UIViewController *VC = [[class alloc]init];
            //tabbar图片
            VC.tabBarItem.image = [[UIImage imageNamed:titleImages[idx]] imageWithRenderingMode:1];
            //tabbar选中图片
            VC.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_pre",titleImages[idx]]] imageWithRenderingMode:1];
            //导航栏标题
            VC.title = titleNames[idx];
            //字体颜色修改
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            //选中
            [dict setValue:[UIColor colorWithHexString:@"#ff3400"] forKey:NSForegroundColorAttributeName];
            [VC.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
            //未选中
            [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(163, 163, 163)} forState:UIControlStateNormal];
            // 跳转tabbar文字跟图片的间距
            VC.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -4);
//            VC.tabBarItem.imageInsets = UIEdgeInsetsMake(-1, 0, 1, 0);
            //添加导航栏
            QJNavigationController *nav = [[QJNavigationController alloc]initWithRootViewController:VC];
            [navArray addObject:nav];
        }];
        //子视图
        _mainTabBarController.viewControllers = navArray;
        //背景颜色
        _mainTabBarController.tabBar.barTintColor = [UIColor whiteColor];
        
        /******如果需要中间按钮凸起圆弧，将此段代码注释解开******/
        /*
        CGFloat WH = 50;
        UIView *bgView = [[UIView alloc]initWithFrame:_mainTabBarController.tabBar.bounds];
        bgView.backgroundColor = YFColor_Background;

        UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, 1)];
        topLine.backgroundColor = [UIColor colorWithHexString:@"dddddd"];
        [bgView addSubview:topLine];
        
        _mainTabBarController.tabBar.barStyle = UIBarStyleBlack;
        
        UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nearby_2"]];
        imgView.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - WH) / 2, -20, WH, WH);
//        imgView.backgroundColor = [UIColor redColor];
        imgView.layer.masksToBounds = YES;
        imgView.layer.cornerRadius = WH/2;
        [bgView addSubview:imgView];
        
        //添加到某一层(栈)
        [_mainTabBarController.tabBar insertSubview:bgView atIndex:0];
         //*/
    }
    return _mainTabBarController;
}



@end
